package lnp;

import static org.junit.Assert.assertTrue;
import lnp.test.RobotTestBed;
import robocode.control.events.RoundEndedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;


/**
 * Illustrates JUnit testing of Robocode robots.
 * This test simply verifies that FiringDock fires the most bullet power 
 * at a still target at least once each round.
 * 
 * @author Lyneth Peou
 *
 */
public class TestFiringDockBulletPower extends RobotTestBed {
  /** True if the robot fires with the highest power at least once. */
  Boolean highestBulletPower = false; 
  /** Initialize the current and previous energy. */
  double previousEnergy = 0.0;
  double currentEnergy = 0.0;   

  /**
   * Specifies that Crazy and FiringDock are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,lnp.FiringDock";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  } 
  /**
   * Tracking the bullet power and enemy's velocity.
   * 
   * @param e details the TurnEndedEvent
   */
  @Override
  public void onTurnEnded(TurnEndedEvent e) {
    int turn = e.getTurnSnapshot().getTurn();
    IRobotSnapshot enemy = e.getTurnSnapshot().getRobots()[0];
    IRobotSnapshot robot = e.getTurnSnapshot().getRobots()[1];    
    
    //Set initial energy
    if (turn == 0) {
      currentEnergy = robot.getEnergy();
    }
    else {
      previousEnergy = currentEnergy;
      currentEnergy = robot.getEnergy();
    }
    
    double BulletPower = previousEnergy - currentEnergy;
    if (enemy.getVelocity() == 0 && BulletPower == 3 && !highestBulletPower) {
      highestBulletPower = true; 
    }
  }
  
  /**
   * Asserts that FiringDock fires hard at the still target.
   * @param e Details about the completed battle.
   */
  public void onRoundEnded(RoundEndedEvent e) {    
    assertTrue("Check FiringDock firing still target", highestBulletPower );   
  }  
  
}
